﻿using MySql.Data.MySqlClient;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CloudApiServer.Services
{
    /// <summary>
    /// 进销存上传服务
    /// </summary>
    public class GoodsService
    {
        /// <summary>
        /// 3501 盘存上传
        /// </summary>
        /// <param name="fsiRequest">入参</param>
        /// <param name="CountrollerName">来源控制器名称</param>
        /// <returns>出参</returns>
        public async Task<bool> GoodsUpload(FsiRequestHeader<InputGoodsUpload> fsiRequest, string CountrollerName)
        {
            string fsiadmvs = fsiRequest.mdtrtarea_admvs.Substring(0, 2);
            string connectionString =
                $"Database={ApiDatainfo.mysqlDatabase};Data Source={ApiDatainfo.mysqlUrl};Port={ApiDatainfo.mysqlPost};UserId={ApiDatainfo.mysqlUser};Password={ApiDatainfo.mysqlPwd};Charset=utf8mb4;TreatTinyAsBoolean=false;Allow User Variables=True";
            using (var conn = new MySqlConnection(connectionString))
            {
                DateTime dateTime = DateTime.Now;
                string InputJson = JsonConvert.SerializeObject(fsiRequest);
                await conn.OpenAsync();
                using (MySqlCommand cmd = conn.CreateCommand())
                {
                    cmd.CommandText =
                        "INSERT INTO fsi_goodsupload  VALUES ( null,@fixmedins_code,@fixmedins_name, @med_list_codg,@fixmedins_hilist_id, @fixmedins_hilist_name, " +
                        "@rx_flag, @invdate, @inv_cnt, @manu_lotnum, @fixmedins_bchno, @manu_date, @expy_end, @memo, 0, @InputJson, @create_time,@update_time)";
                    cmd.Parameters.AddWithValue("@fixmedins_code", fsiRequest.fixmedins_code);
                    cmd.Parameters.AddWithValue("@fixmedins_name", fsiRequest.fixmedins_name);
                    cmd.Parameters.AddWithValue("@med_list_codg", fsiRequest.Input.invinfo.med_list_codg);
                    cmd.Parameters.AddWithValue("@fixmedins_hilist_id", fsiRequest.Input.invinfo.fixmedins_hilist_id);
                    cmd.Parameters.AddWithValue("@fixmedins_hilist_name",
                        fsiRequest.Input.invinfo.fixmedins_hilist_name);
                    cmd.Parameters.AddWithValue("@rx_flag", fsiRequest.Input.invinfo.rx_flag);
                    cmd.Parameters.AddWithValue("@invdate", fsiRequest.Input.invinfo.invdate);
                    cmd.Parameters.AddWithValue("@inv_cnt", fsiRequest.Input.invinfo.inv_cnt);
                    cmd.Parameters.AddWithValue("@manu_lotnum", fsiRequest.Input.invinfo.manu_lotnum);
                    cmd.Parameters.AddWithValue("@fixmedins_bchno", fsiRequest.Input.invinfo.fixmedins_bchno);
                    cmd.Parameters.AddWithValue("@manu_date", fsiRequest.Input.invinfo.manu_date);
                    cmd.Parameters.AddWithValue("@expy_end", fsiRequest.Input.invinfo.expy_end);
                    cmd.Parameters.AddWithValue("@memo", fsiRequest.Input.invinfo.memo);
                    cmd.Parameters.AddWithValue("@InputJson", InputJson);
                    cmd.Parameters.AddWithValue("@create_time", dateTime.ToString("yyyy-MM-dd HH-mm-ss"));
                    cmd.Parameters.AddWithValue("@update_time", dateTime.ToString("yyyy-MM-dd HH-mm-ss"));
                    await cmd.ExecuteNonQueryAsync();
                    cmd.Parameters.Clear();
                }

                return true;
            }
        }

        /// <summary>
        /// 3502 库存变更
        /// </summary>
        /// <param name="fsiRequest">入参</param>
        /// <param name="CountrollerName">来源控制器名称</param>
        /// <returns>出参</returns>
        public async Task<bool> GoodsUpdate(FsiRequestHeader<InputGoodsUpdate> fsiRequest, string CountrollerName)
        {
            string fsiadmvs = fsiRequest.mdtrtarea_admvs.Substring(0, 2);
            string connectionString =
                $"Database={ApiDatainfo.mysqlDatabase};Data Source={ApiDatainfo.mysqlUrl};Port={ApiDatainfo.mysqlPost};UserId={ApiDatainfo.mysqlUser};Password={ApiDatainfo.mysqlPwd};Charset=utf8mb4;TreatTinyAsBoolean=false;Allow User Variables=True";
            using (var conn = new MySqlConnection(connectionString))
            {
                DateTime dateTime = DateTime.Now;
                string InputJson = JsonConvert.SerializeObject(fsiRequest);
                await conn.OpenAsync();
                using (MySqlCommand cmd = conn.CreateCommand())
                {
                    cmd.CommandText =
                        "INSERT INTO fsi_goodsupdate  VALUES ( null,@fixmedins_code,@fixmedins_name, @med_list_codg,@inv_chg_type,@fixmedins_hilist_id, @fixmedins_hilist_name, " +
                        "@fixmedins_bchno, @pric, @cnt, @rx_flag, @inv_chg_time, @inv_chg_opter_name, @memo, @trdn_flag, 0, @InputJson, @create_time,@update_time)";
                    cmd.Parameters.AddWithValue("@fixmedins_code", fsiRequest.fixmedins_code);
                    cmd.Parameters.AddWithValue("@fixmedins_name", fsiRequest.fixmedins_name);
                    cmd.Parameters.AddWithValue("@med_list_codg", fsiRequest.Input.invinfo.med_list_codg);
                    cmd.Parameters.AddWithValue("@fixmedins_hilist_id", fsiRequest.Input.invinfo.fixmedins_hilist_id);
                    cmd.Parameters.AddWithValue("@fixmedins_hilist_name",
                        fsiRequest.Input.invinfo.fixmedins_hilist_name);
                    cmd.Parameters.AddWithValue("@fixmedins_bchno", fsiRequest.Input.invinfo.fixmedins_bchno);
                    cmd.Parameters.AddWithValue("@inv_chg_type", fsiRequest.Input.invinfo.inv_chg_type);
                    cmd.Parameters.AddWithValue("@rx_flag", fsiRequest.Input.invinfo.rx_flag);
                    cmd.Parameters.AddWithValue("@pric", fsiRequest.Input.invinfo.pric);
                    cmd.Parameters.AddWithValue("@cnt", fsiRequest.Input.invinfo.cnt);
                    cmd.Parameters.AddWithValue("@inv_chg_time", fsiRequest.Input.invinfo.inv_chg_time);
                    cmd.Parameters.AddWithValue("@inv_chg_opter_name", fsiRequest.Input.invinfo.inv_chg_opter_name);
                    cmd.Parameters.AddWithValue("@trdn_flag", fsiRequest.Input.invinfo.trdn_flag);
                    cmd.Parameters.AddWithValue("@memo", fsiRequest.Input.invinfo.memo);
                    cmd.Parameters.AddWithValue("@InputJson", InputJson);
                    cmd.Parameters.AddWithValue("@create_time", dateTime.ToString("yyyy-MM-dd HH-mm-ss"));
                    cmd.Parameters.AddWithValue("@update_time", dateTime.ToString("yyyy-MM-dd HH-mm-ss"));
                    await cmd.ExecuteNonQueryAsync();
                    cmd.Parameters.Clear();
                }

                return true;
            }
        }

        /// <summary>
        /// 3503 采购上传
        /// </summary>
        /// <param name="fsiRequest">入参</param>
        /// <param name="CountrollerName">来源控制器名称</param>
        /// <returns>出参</returns>
        public async Task<bool> GoodsBuy(FsiRequestHeader<InputGoodsBuy> fsiRequest, string CountrollerName)
        {
            string fsiadmvs = fsiRequest.mdtrtarea_admvs.Substring(0, 2);
            string connectionString =
                $"Database={ApiDatainfo.mysqlDatabase};Data Source={ApiDatainfo.mysqlUrl};Port={ApiDatainfo.mysqlPost};UserId={ApiDatainfo.mysqlUser};Password={ApiDatainfo.mysqlPwd};Charset=utf8mb4;TreatTinyAsBoolean=false;Allow User Variables=True";
            using (var conn = new MySqlConnection(connectionString))
            {
                DateTime dateTime = DateTime.Now;
                string InputJson = JsonConvert.SerializeObject(fsiRequest);
                await conn.OpenAsync();
                using (MySqlCommand cmd = conn.CreateCommand())
                {
                    cmd.CommandText =
                        "INSERT INTO fsi_goodsbuy  VALUES ( null,@fixmedins_code,@fixmedins_name,@med_list_codg,@fixmedins_hilist_id," +
                        " @fixmedins_hilist_name,@dynt_no,@fixmedins_bchno,@spler_name,@spler_pmtno," +
                        " @manu_lotnum,@prodentp_name, @aprvno, @manu_date,@expy_end," +
                        "@finl_trns_pric,@purc_retn_cnt,@purc_invo_codg,@purc_invo_no, @rx_flag," +
                        " @purc_retn_stoin_time, @purc_retn_opter_name, @prod_geay_flag,@memo,0,0," +
                        " @InputJson, @create_time,@update_time)";
                    cmd.Parameters.AddWithValue("@fixmedins_code", fsiRequest.fixmedins_code);
                    cmd.Parameters.AddWithValue("@fixmedins_name", fsiRequest.fixmedins_name);
                    cmd.Parameters.AddWithValue("@med_list_codg", fsiRequest.Input.purcinfo.med_list_codg);
                    cmd.Parameters.AddWithValue("@fixmedins_hilist_id", fsiRequest.Input.purcinfo.fixmedins_hilist_id);
                    cmd.Parameters.AddWithValue("@fixmedins_hilist_name",
                        fsiRequest.Input.purcinfo.fixmedins_hilist_name);

                    cmd.Parameters.AddWithValue("@dynt_no", fsiRequest.Input.purcinfo.dynt_no);
                    cmd.Parameters.AddWithValue("@fixmedins_bchno", fsiRequest.Input.purcinfo.fixmedins_bchno);
                    cmd.Parameters.AddWithValue("@spler_name", fsiRequest.Input.purcinfo.spler_name);
                    cmd.Parameters.AddWithValue("@spler_pmtno", fsiRequest.Input.purcinfo.spler_pmtno);
                    cmd.Parameters.AddWithValue("@manu_lotnum", fsiRequest.Input.purcinfo.manu_lotnum);

                    cmd.Parameters.AddWithValue("@prodentp_name", fsiRequest.Input.purcinfo.prodentp_name);
                    cmd.Parameters.AddWithValue("@aprvno", fsiRequest.Input.purcinfo.aprvno);
                    cmd.Parameters.AddWithValue("@manu_date", fsiRequest.Input.purcinfo.manu_date);
                    cmd.Parameters.AddWithValue("@expy_end", fsiRequest.Input.purcinfo.expy_end);
                    cmd.Parameters.AddWithValue("@finl_trns_pric", fsiRequest.Input.purcinfo.finl_trns_pric);

                    cmd.Parameters.AddWithValue("@purc_retn_cnt", fsiRequest.Input.purcinfo.purc_retn_cnt);
                    cmd.Parameters.AddWithValue("@purc_invo_codg", fsiRequest.Input.purcinfo.purc_invo_codg);
                    cmd.Parameters.AddWithValue("@purc_invo_no", fsiRequest.Input.purcinfo.purc_invo_no);
                    cmd.Parameters.AddWithValue("@rx_flag", fsiRequest.Input.purcinfo.rx_flag);
                    cmd.Parameters.AddWithValue("@purc_retn_stoin_time",
                        fsiRequest.Input.purcinfo.purc_retn_stoin_time);

                    cmd.Parameters.AddWithValue("@purc_retn_opter_name",
                        fsiRequest.Input.purcinfo.purc_retn_opter_name);
                    cmd.Parameters.AddWithValue("@prod_geay_flag", fsiRequest.Input.purcinfo.prod_geay_flag);
                    cmd.Parameters.AddWithValue("@memo", fsiRequest.Input.purcinfo.memo);
                    cmd.Parameters.AddWithValue("@InputJson", InputJson);
                    cmd.Parameters.AddWithValue("@create_time", dateTime.ToString("yyyy-MM-dd HH-mm-ss"));
                    cmd.Parameters.AddWithValue("@update_time", dateTime.ToString("yyyy-MM-dd HH-mm-ss"));
                    await cmd.ExecuteNonQueryAsync();
                    cmd.Parameters.Clear();
                }

                return true;
            }
        }

        /// <summary>
        /// 3504 采购退货上传
        /// </summary>
        /// <param name="fsiRequest">入参</param>
        /// <param name="CountrollerName">来源控制器名称</param>
        /// <returns>出参</returns>
        public async Task<bool> GoodsBuyReturn(FsiRequestHeader<InputGoodsBuy> fsiRequest, string CountrollerName)
        {
            string fsiadmvs = fsiRequest.mdtrtarea_admvs.Substring(0, 2);
            string connectionString =
                $"Database={ApiDatainfo.mysqlDatabase};Data Source={ApiDatainfo.mysqlUrl};Port={ApiDatainfo.mysqlPost};UserId={ApiDatainfo.mysqlUser};Password={ApiDatainfo.mysqlPwd};Charset=utf8mb4;TreatTinyAsBoolean=false;Allow User Variables=True";
            using (var conn = new MySqlConnection(connectionString))
            {
                DateTime dateTime = DateTime.Now;
                string InputJson = JsonConvert.SerializeObject(fsiRequest);
                await conn.OpenAsync();
                using (MySqlCommand cmd = conn.CreateCommand())
                {
                    cmd.CommandText =
                        "select * from fsi_goodsbuy  where fixmedins_code =@fixmedins_code and med_list_codg =@med_list_codg and fixmedins_hilist_id =@fixmedins_hilist_id and fixmedins_bchno=@fixmedins_bchno and state =0 and datatype=0";
                    cmd.Parameters.AddWithValue("@fixmedins_code", fsiRequest.fixmedins_code);
                    cmd.Parameters.AddWithValue("@med_list_codg", fsiRequest.Input.purcinfo.med_list_codg);
                    cmd.Parameters.AddWithValue("@fixmedins_hilist_id", fsiRequest.Input.purcinfo.fixmedins_hilist_id);
                    cmd.Parameters.AddWithValue("@fixmedins_bchno", fsiRequest.Input.purcinfo.fixmedins_bchno);
                    using (MySqlDataReader reader = (MySqlDataReader)await cmd.ExecuteReaderAsync())
                    {
                        cmd.Parameters.Clear();
                        DataTable dt = new DataTable();
                        dt.Load(reader);
                        if (dt.Rows.Count < 1)
                        {
                            throw new Exception(
                                $"查询采购上传记录表失败！根据传入的机构代码【{fsiRequest.fixmedins_code}】医保目录编码【{fsiRequest.Input.purcinfo.med_list_codg}】医疗机构内部编码【{fsiRequest.Input.purcinfo.fixmedins_hilist_id}】批次号【{fsiRequest.Input.purcinfo.fixmedins_bchno}】查询到的采购上传记录总数为：{dt.Rows.Count}");
                        }
                        else
                        {
                            cmd.CommandText =
                                "INSERT INTO fsi_goodsbuy  VALUES ( null,@fixmedins_code,@fixmedins_name,@med_list_codg,@fixmedins_hilist_id," +
                                " @fixmedins_hilist_name,@dynt_no,@fixmedins_bchno,@spler_name,@spler_pmtno," +
                                " @manu_lotnum,@prodentp_name, @aprvno, @manu_date,@expy_end," +
                                "@finl_trns_pric,@purc_retn_cnt,@purc_invo_codg,@purc_invo_no, @rx_flag," +
                                " @purc_retn_stoin_time, @purc_retn_opter_name, @prod_geay_flag,@memo, 1,0," +
                                " @InputJson, @create_time,@update_time)";
                            cmd.Parameters.AddWithValue("@fixmedins_code", fsiRequest.fixmedins_code);
                            cmd.Parameters.AddWithValue("@fixmedins_name", fsiRequest.fixmedins_name);
                            cmd.Parameters.AddWithValue("@med_list_codg", fsiRequest.Input.purcinfo.med_list_codg);
                            cmd.Parameters.AddWithValue("@fixmedins_hilist_id",
                                fsiRequest.Input.purcinfo.fixmedins_hilist_id);
                            cmd.Parameters.AddWithValue("@fixmedins_hilist_name",
                                fsiRequest.Input.purcinfo.fixmedins_hilist_name);

                            cmd.Parameters.AddWithValue("@dynt_no", fsiRequest.Input.purcinfo.dynt_no);
                            cmd.Parameters.AddWithValue("@fixmedins_bchno", fsiRequest.Input.purcinfo.fixmedins_bchno);
                            cmd.Parameters.AddWithValue("@spler_name", fsiRequest.Input.purcinfo.spler_name);
                            cmd.Parameters.AddWithValue("@spler_pmtno", fsiRequest.Input.purcinfo.spler_pmtno);
                            cmd.Parameters.AddWithValue("@manu_lotnum", fsiRequest.Input.purcinfo.manu_lotnum);

                            cmd.Parameters.AddWithValue("@prodentp_name", fsiRequest.Input.purcinfo.prodentp_name);
                            cmd.Parameters.AddWithValue("@aprvno", fsiRequest.Input.purcinfo.aprvno);
                            cmd.Parameters.AddWithValue("@manu_date", fsiRequest.Input.purcinfo.manu_date);
                            cmd.Parameters.AddWithValue("@expy_end", fsiRequest.Input.purcinfo.expy_end);
                            cmd.Parameters.AddWithValue("@finl_trns_pric", fsiRequest.Input.purcinfo.finl_trns_pric);

                            cmd.Parameters.AddWithValue("@purc_retn_cnt", fsiRequest.Input.purcinfo.purc_retn_cnt);
                            cmd.Parameters.AddWithValue("@purc_invo_codg", fsiRequest.Input.purcinfo.purc_invo_codg);
                            cmd.Parameters.AddWithValue("@purc_invo_no", fsiRequest.Input.purcinfo.purc_invo_no);
                            cmd.Parameters.AddWithValue("@rx_flag", fsiRequest.Input.purcinfo.rx_flag);
                            cmd.Parameters.AddWithValue("@purc_retn_stoin_time",
                                fsiRequest.Input.purcinfo.purc_retn_stoin_time);

                            cmd.Parameters.AddWithValue("@purc_retn_opter_name",
                                fsiRequest.Input.purcinfo.purc_retn_opter_name);
                            cmd.Parameters.AddWithValue("@prod_geay_flag", fsiRequest.Input.purcinfo.prod_geay_flag);
                            cmd.Parameters.AddWithValue("@memo", fsiRequest.Input.purcinfo.memo);
                            cmd.Parameters.AddWithValue("@InputJson", InputJson);
                            cmd.Parameters.AddWithValue("@create_time", dateTime.ToString("yyyy-MM-dd HH-mm-ss"));
                            cmd.Parameters.AddWithValue("@update_time", dateTime.ToString("yyyy-MM-dd HH-mm-ss"));
                            await cmd.ExecuteNonQueryAsync();
                            cmd.Parameters.Clear();
                            return true;
                        }
                    }
                }
            }
        }

        /// <summary>
        /// 3505 销售上传
        /// </summary>
        /// <param name="fsiRequest">入参</param>
        /// <param name="CountrollerName">来源控制器名称</param>
        /// <returns>出参</returns>
        public async Task<bool> GoodsSell(FsiRequestHeader<InputGoodsSell> fsiRequest, string CountrollerName)
        {
            string fsiadmvs = fsiRequest.mdtrtarea_admvs.Substring(0, 2);
            string connectionString =
                $"Database={ApiDatainfo.mysqlDatabase};Data Source={ApiDatainfo.mysqlUrl};Port={ApiDatainfo.mysqlPost};UserId={ApiDatainfo.mysqlUser};Password={ApiDatainfo.mysqlPwd};Charset=utf8mb4;TreatTinyAsBoolean=false;Allow User Variables=True";
            using (var conn = new MySqlConnection(connectionString))
            {
                DateTime dateTime = DateTime.Now;
                string InputJson = JsonConvert.SerializeObject(fsiRequest);
                await conn.OpenAsync();
                using (MySqlCommand cmd = conn.CreateCommand())
                {
                    cmd.CommandText = "INSERT INTO fsi_goodsSell VALUES ( " +
                                      " null,@fixmedins_code,@fixmedins_name,@med_list_codg,@fixmedins_hilist_id," +
                                      " @fixmedins_hilist_name,@fixmedins_bchno,@prsc_dr_cert_type,@prsc_dr_certno,@prsc_dr_name," +
                                      " @phar_cert_type,@phar_certno, @phar_name, @phar_prac_cert_no,@hi_feesetl_type," +
                                      " @setl_id,@mdtrt_sn,@psn_no,@psn_cert_type, @certno," +
                                      " @psn_name, @manu_lotnum, @manu_date,@expy_end,@rx_flag," +
                                      " @trdn_flag, @finl_trns_pric, @rxno,@rx_circ_flag,@rtal_docno," +
                                      " @stoout_no, @bchno, @drug_trac_codg,@drug_prod_barc,@shelf_posi," +
                                      " @sel_retn_cnt, @sel_retn_time, @sel_retn_opter_name,@memo,@mdtrt_setl_type," +
                                      " 0,0,@InputJson, @create_time,@update_time)";
                    cmd.Parameters.AddWithValue("@fixmedins_code", fsiRequest.fixmedins_code);
                    cmd.Parameters.AddWithValue("@fixmedins_name", fsiRequest.fixmedins_name);
                    cmd.Parameters.AddWithValue("@med_list_codg", fsiRequest.Input.selinfo.med_list_codg);
                    cmd.Parameters.AddWithValue("@fixmedins_hilist_id", fsiRequest.Input.selinfo.fixmedins_hilist_id);

                    cmd.Parameters.AddWithValue("@fixmedins_hilist_name",
                        fsiRequest.Input.selinfo.fixmedins_hilist_name);
                    cmd.Parameters.AddWithValue("@fixmedins_bchno", fsiRequest.Input.selinfo.fixmedins_bchno);
                    cmd.Parameters.AddWithValue("@prsc_dr_cert_type", fsiRequest.Input.selinfo.prsc_dr_cert_type);
                    cmd.Parameters.AddWithValue("@prsc_dr_certno", fsiRequest.Input.selinfo.prsc_dr_certno);
                    cmd.Parameters.AddWithValue("@prsc_dr_name", fsiRequest.Input.selinfo.prsc_dr_name);

                    cmd.Parameters.AddWithValue("@phar_cert_type", fsiRequest.Input.selinfo.phar_cert_type);
                    cmd.Parameters.AddWithValue("@phar_certno", fsiRequest.Input.selinfo.phar_certno);
                    cmd.Parameters.AddWithValue("@phar_name", fsiRequest.Input.selinfo.phar_name);
                    cmd.Parameters.AddWithValue("@phar_prac_cert_no", fsiRequest.Input.selinfo.phar_prac_cert_no);
                    cmd.Parameters.AddWithValue("@hi_feesetl_type", fsiRequest.Input.selinfo.hi_feesetl_type);

                    cmd.Parameters.AddWithValue("@setl_id", fsiRequest.Input.selinfo.setl_id);
                    cmd.Parameters.AddWithValue("@mdtrt_sn", fsiRequest.Input.selinfo.mdtrt_sn);
                    cmd.Parameters.AddWithValue("@psn_no", fsiRequest.Input.selinfo.psn_no);
                    cmd.Parameters.AddWithValue("@psn_cert_type", fsiRequest.Input.selinfo.psn_cert_type);
                    cmd.Parameters.AddWithValue("@certno", fsiRequest.Input.selinfo.certno);

                    cmd.Parameters.AddWithValue("@psn_name", fsiRequest.Input.selinfo.psn_name);
                    cmd.Parameters.AddWithValue("@manu_lotnum", fsiRequest.Input.selinfo.manu_lotnum);
                    cmd.Parameters.AddWithValue("@manu_date", fsiRequest.Input.selinfo.manu_date);
                    cmd.Parameters.AddWithValue("@expy_end", fsiRequest.Input.selinfo.expy_end);
                    cmd.Parameters.AddWithValue("@rx_flag", fsiRequest.Input.selinfo.rx_flag);

                    cmd.Parameters.AddWithValue("@trdn_flag", fsiRequest.Input.selinfo.trdn_flag);
                    cmd.Parameters.AddWithValue("@finl_trns_pric", fsiRequest.Input.selinfo.finl_trns_pric);
                    cmd.Parameters.AddWithValue("@rxno", fsiRequest.Input.selinfo.rxno);
                    cmd.Parameters.AddWithValue("@rx_circ_flag", fsiRequest.Input.selinfo.rx_circ_flag);
                    cmd.Parameters.AddWithValue("@rtal_docno", fsiRequest.Input.selinfo.rtal_docno);

                    cmd.Parameters.AddWithValue("@stoout_no", fsiRequest.Input.selinfo.stoout_no);
                    cmd.Parameters.AddWithValue("@bchno", fsiRequest.Input.selinfo.bchno);
                    cmd.Parameters.AddWithValue("@drug_trac_codg", fsiRequest.Input.selinfo.drug_trac_codg);
                    cmd.Parameters.AddWithValue("@drug_prod_barc", fsiRequest.Input.selinfo.drug_prod_barc);
                    cmd.Parameters.AddWithValue("@shelf_posi", fsiRequest.Input.selinfo.shelf_posi);

                    cmd.Parameters.AddWithValue("@sel_retn_cnt", fsiRequest.Input.selinfo.sel_retn_cnt);
                    cmd.Parameters.AddWithValue("@sel_retn_time", fsiRequest.Input.selinfo.sel_retn_time);
                    cmd.Parameters.AddWithValue("@sel_retn_opter_name", fsiRequest.Input.selinfo.sel_retn_opter_name);
                    cmd.Parameters.AddWithValue("@memo", fsiRequest.Input.selinfo.memo);
                    cmd.Parameters.AddWithValue("@mdtrt_setl_type", fsiRequest.Input.selinfo.mdtrt_setl_type);


                    cmd.Parameters.AddWithValue("@InputJson", InputJson);
                    cmd.Parameters.AddWithValue("@create_time", dateTime.ToString("yyyy-MM-dd HH-mm-ss"));
                    cmd.Parameters.AddWithValue("@update_time", dateTime.ToString("yyyy-MM-dd HH-mm-ss"));
                    await cmd.ExecuteNonQueryAsync();
                    cmd.Parameters.Clear();
                }

                return true;
            }
        }

        /// <summary>
        /// 3506 销售退货上传
        /// </summary>
        /// <param name="fsiRequest">入参</param>
        /// <param name="CountrollerName">来源控制器名称</param>
        /// <returns>出参</returns>
        public async Task<bool> GoodsSellReturn(FsiRequestHeader<InputGoodsSell> fsiRequest, string CountrollerName)
        {
            string fsiadmvs = fsiRequest.mdtrtarea_admvs.Substring(0, 2);
            string connectionString =
                $"Database={ApiDatainfo.mysqlDatabase};Data Source={ApiDatainfo.mysqlUrl};Port={ApiDatainfo.mysqlPost};UserId={ApiDatainfo.mysqlUser};Password={ApiDatainfo.mysqlPwd};Charset=utf8mb4;TreatTinyAsBoolean=false;Allow User Variables=True";
            using (var conn = new MySqlConnection(connectionString))
            {
                DateTime dateTime = DateTime.Now;
                string InputJson = JsonConvert.SerializeObject(fsiRequest);
                await conn.OpenAsync();
                using (MySqlCommand cmd = conn.CreateCommand())
                {
                    cmd.CommandText =
                        "select * from fsi_goodsSell  where fixmedins_code =@fixmedins_code and med_list_codg =@med_list_codg and fixmedins_hilist_id =@fixmedins_hilist_id and fixmedins_bchno=@fixmedins_bchno and state =0 and datatype=0";
                    cmd.Parameters.AddWithValue("@fixmedins_code", fsiRequest.fixmedins_code);
                    cmd.Parameters.AddWithValue("@med_list_codg", fsiRequest.Input.selinfo.med_list_codg);
                    cmd.Parameters.AddWithValue("@fixmedins_hilist_id", fsiRequest.Input.selinfo.fixmedins_hilist_id);
                    cmd.Parameters.AddWithValue("@fixmedins_bchno", fsiRequest.Input.selinfo.fixmedins_bchno);
                    using (MySqlDataReader reader = (MySqlDataReader)await cmd.ExecuteReaderAsync())
                    {
                        cmd.Parameters.Clear();
                        DataTable dt = new DataTable();
                        dt.Load(reader);
                        if (dt.Rows.Count < 1)
                        {
                            throw new Exception(
                                $"查询销售上传记录表失败！根据传入的机构代码【{fsiRequest.fixmedins_code}】医保目录编码【{fsiRequest.Input.selinfo.med_list_codg}】医疗机构内部编码【{fsiRequest.Input.selinfo.fixmedins_hilist_id}】批次号【{fsiRequest.Input.selinfo.fixmedins_bchno}】查询到的销售上传记录总数为：{dt.Rows.Count}");
                        }
                        else
                        {
                            cmd.CommandText = "INSERT INTO fsi_goodsSell VALUES ( " +
                                              " null,@fixmedins_code,@fixmedins_name,@med_list_codg,@fixmedins_hilist_id," +
                                              " @fixmedins_hilist_name,@fixmedins_bchno,@prsc_dr_cert_type,@prsc_dr_certno,@prsc_dr_name," +
                                              " @phar_cert_type,@phar_certno, @phar_name, @phar_prac_cert_no,@hi_feesetl_type," +
                                              " @setl_id,@mdtrt_sn,@psn_no,@psn_cert_type, @certno," +
                                              " @psn_name, @manu_lotnum, @manu_date,@expy_end,@rx_flag," +
                                              " @trdn_flag, @finl_trns_pric, @rxno,@rx_circ_flag,@rtal_docno," +
                                              " @stoout_no, @bchno, @drug_trac_codg,@drug_prod_barc,@shelf_posi," +
                                              " @sel_retn_cnt, @sel_retn_time, @sel_retn_opter_name,@memo,@mdtrt_setl_type," +
                                              " 1,0,@InputJson, @create_time,@update_time)";
                            cmd.Parameters.AddWithValue("@fixmedins_code", fsiRequest.fixmedins_code);
                            cmd.Parameters.AddWithValue("@fixmedins_name", fsiRequest.fixmedins_name);
                            cmd.Parameters.AddWithValue("@med_list_codg", fsiRequest.Input.selinfo.med_list_codg);
                            cmd.Parameters.AddWithValue("@fixmedins_hilist_id",
                                fsiRequest.Input.selinfo.fixmedins_hilist_id);

                            cmd.Parameters.AddWithValue("@fixmedins_hilist_name",
                                fsiRequest.Input.selinfo.fixmedins_hilist_name);
                            cmd.Parameters.AddWithValue("@fixmedins_bchno", fsiRequest.Input.selinfo.fixmedins_bchno);
                            cmd.Parameters.AddWithValue("@prsc_dr_cert_type",
                                fsiRequest.Input.selinfo.prsc_dr_cert_type);
                            cmd.Parameters.AddWithValue("@prsc_dr_certno", fsiRequest.Input.selinfo.prsc_dr_certno);
                            cmd.Parameters.AddWithValue("@prsc_dr_name", fsiRequest.Input.selinfo.prsc_dr_name);

                            cmd.Parameters.AddWithValue("@phar_cert_type", fsiRequest.Input.selinfo.phar_cert_type);
                            cmd.Parameters.AddWithValue("@phar_certno", fsiRequest.Input.selinfo.phar_certno);
                            cmd.Parameters.AddWithValue("@phar_name", fsiRequest.Input.selinfo.phar_name);
                            cmd.Parameters.AddWithValue("@phar_prac_cert_no",
                                fsiRequest.Input.selinfo.phar_prac_cert_no);
                            cmd.Parameters.AddWithValue("@hi_feesetl_type", fsiRequest.Input.selinfo.hi_feesetl_type);

                            cmd.Parameters.AddWithValue("@setl_id", fsiRequest.Input.selinfo.setl_id);
                            cmd.Parameters.AddWithValue("@mdtrt_sn", fsiRequest.Input.selinfo.mdtrt_sn);
                            cmd.Parameters.AddWithValue("@psn_no", fsiRequest.Input.selinfo.psn_no);
                            cmd.Parameters.AddWithValue("@psn_cert_type", fsiRequest.Input.selinfo.psn_cert_type);
                            cmd.Parameters.AddWithValue("@certno", fsiRequest.Input.selinfo.certno);

                            cmd.Parameters.AddWithValue("@psn_name", fsiRequest.Input.selinfo.psn_name);
                            cmd.Parameters.AddWithValue("@manu_lotnum", fsiRequest.Input.selinfo.manu_lotnum);
                            cmd.Parameters.AddWithValue("@manu_date", fsiRequest.Input.selinfo.manu_date);
                            cmd.Parameters.AddWithValue("@expy_end", fsiRequest.Input.selinfo.expy_end);
                            cmd.Parameters.AddWithValue("@rx_flag", fsiRequest.Input.selinfo.rx_flag);

                            cmd.Parameters.AddWithValue("@trdn_flag", fsiRequest.Input.selinfo.trdn_flag);
                            cmd.Parameters.AddWithValue("@finl_trns_pric", fsiRequest.Input.selinfo.finl_trns_pric);
                            cmd.Parameters.AddWithValue("@rxno", fsiRequest.Input.selinfo.rxno);
                            cmd.Parameters.AddWithValue("@rx_circ_flag", fsiRequest.Input.selinfo.rx_circ_flag);
                            cmd.Parameters.AddWithValue("@rtal_docno", fsiRequest.Input.selinfo.rtal_docno);

                            cmd.Parameters.AddWithValue("@stoout_no", fsiRequest.Input.selinfo.stoout_no);
                            cmd.Parameters.AddWithValue("@bchno", fsiRequest.Input.selinfo.bchno);
                            cmd.Parameters.AddWithValue("@drug_trac_codg", fsiRequest.Input.selinfo.drug_trac_codg);
                            cmd.Parameters.AddWithValue("@drug_prod_barc", fsiRequest.Input.selinfo.drug_prod_barc);
                            cmd.Parameters.AddWithValue("@shelf_posi", fsiRequest.Input.selinfo.shelf_posi);

                            cmd.Parameters.AddWithValue("@sel_retn_cnt", fsiRequest.Input.selinfo.sel_retn_cnt);
                            cmd.Parameters.AddWithValue("@sel_retn_time", fsiRequest.Input.selinfo.sel_retn_time);
                            cmd.Parameters.AddWithValue("@sel_retn_opter_name",
                                fsiRequest.Input.selinfo.sel_retn_opter_name);
                            cmd.Parameters.AddWithValue("@memo", fsiRequest.Input.selinfo.memo);
                            cmd.Parameters.AddWithValue("@mdtrt_setl_type", fsiRequest.Input.selinfo.mdtrt_setl_type);


                            cmd.Parameters.AddWithValue("@InputJson", InputJson);
                            cmd.Parameters.AddWithValue("@create_time", dateTime.ToString("yyyy-MM-dd HH-mm-ss"));
                            cmd.Parameters.AddWithValue("@update_time", dateTime.ToString("yyyy-MM-dd HH-mm-ss"));
                            await cmd.ExecuteNonQueryAsync();
                            cmd.Parameters.Clear();
                            return true;
                        }
                    }
                }
            }
        }

        /// <summary>
        /// 3506 销售退货上传 数组
        /// </summary>
        /// <param name="fsiRequest">入参</param>
        /// <param name="CountrollerName">来源控制器名称</param>
        /// <returns>出参</returns>
        public async Task<bool> GoodsSellReturnList(FsiRequestHeader<InputGoodsSellList> fsiRequest,
            string CountrollerName)
        {
            string fsiadmvs = fsiRequest.mdtrtarea_admvs.Substring(0, 2);
            string connectionString =
                $"Database={ApiDatainfo.mysqlDatabase};Data Source={ApiDatainfo.mysqlUrl};Port={ApiDatainfo.mysqlPost};UserId={ApiDatainfo.mysqlUser};Password={ApiDatainfo.mysqlPwd};Charset=utf8mb4;TreatTinyAsBoolean=false;Allow User Variables=True";
            using (var conn = new MySqlConnection(connectionString))
            {
                DateTime dateTime = DateTime.Now;
                string InputJson = JsonConvert.SerializeObject(fsiRequest);
                await conn.OpenAsync();
                using (MySqlCommand cmd = conn.CreateCommand())
                {
                    foreach (var item in fsiRequest.Input.selinfo)
                    {
                        cmd.CommandText =
                            "select * from fsi_goodsSell  where fixmedins_code =@fixmedins_code and med_list_codg =@med_list_codg and fixmedins_hilist_id =@fixmedins_hilist_id and fixmedins_bchno=@fixmedins_bchno and state =0 and datatype=0";
                        cmd.Parameters.AddWithValue("@fixmedins_code", fsiRequest.fixmedins_code);
                        cmd.Parameters.AddWithValue("@med_list_codg", item.med_list_codg);
                        cmd.Parameters.AddWithValue("@fixmedins_hilist_id", item.fixmedins_hilist_id);
                        cmd.Parameters.AddWithValue("@fixmedins_bchno", item.fixmedins_bchno);
                        using (MySqlDataReader reader = (MySqlDataReader)await cmd.ExecuteReaderAsync())
                        {
                            cmd.Parameters.Clear();
                            DataTable dt = new DataTable();
                            dt.Load(reader);
                            if (dt.Rows.Count < 1)
                            {
                                throw new Exception(
                                    $"查询销售上传记录表失败！根据传入的机构代码【{fsiRequest.fixmedins_code}】医保目录编码【{item.med_list_codg}】医疗机构内部编码【{item.fixmedins_hilist_id}】批次号【{item.fixmedins_bchno}】查询到的销售上传记录总数为：{dt.Rows.Count}");
                            }
                            else
                            {
                                cmd.CommandText = "INSERT INTO fsi_goodsSell VALUES ( " +
                                                  " null,@fixmedins_code,@fixmedins_name,@med_list_codg,@fixmedins_hilist_id," +
                                                  " @fixmedins_hilist_name,@fixmedins_bchno,@prsc_dr_cert_type,@prsc_dr_certno,@prsc_dr_name," +
                                                  " @phar_cert_type,@phar_certno, @phar_name, @phar_prac_cert_no,@hi_feesetl_type," +
                                                  " @setl_id,@mdtrt_sn,@psn_no,@psn_cert_type, @certno," +
                                                  " @psn_name, @manu_lotnum, @manu_date,@expy_end,@rx_flag," +
                                                  " @trdn_flag, @finl_trns_pric, @rxno,@rx_circ_flag,@rtal_docno," +
                                                  " @stoout_no, @bchno, @drug_trac_codg,@drug_prod_barc,@shelf_posi," +
                                                  " @sel_retn_cnt, @sel_retn_time, @sel_retn_opter_name,@memo,@mdtrt_setl_type," +
                                                  " 1,0,@InputJson, @create_time,@update_time)";
                                cmd.Parameters.AddWithValue("@fixmedins_code", fsiRequest.fixmedins_code);
                                cmd.Parameters.AddWithValue("@fixmedins_name", fsiRequest.fixmedins_name);
                                cmd.Parameters.AddWithValue("@med_list_codg", item.med_list_codg);
                                cmd.Parameters.AddWithValue("@fixmedins_hilist_id", item.fixmedins_hilist_id);

                                cmd.Parameters.AddWithValue("@fixmedins_hilist_name", item.fixmedins_hilist_name);
                                cmd.Parameters.AddWithValue("@fixmedins_bchno", item.fixmedins_bchno);
                                cmd.Parameters.AddWithValue("@prsc_dr_cert_type", item.prsc_dr_cert_type);
                                cmd.Parameters.AddWithValue("@prsc_dr_certno", item.prsc_dr_certno);
                                cmd.Parameters.AddWithValue("@prsc_dr_name", item.prsc_dr_name);

                                cmd.Parameters.AddWithValue("@phar_cert_type", item.phar_cert_type);
                                cmd.Parameters.AddWithValue("@phar_certno", item.phar_certno);
                                cmd.Parameters.AddWithValue("@phar_name", item.phar_name);
                                cmd.Parameters.AddWithValue("@phar_prac_cert_no", item.phar_prac_cert_no);
                                cmd.Parameters.AddWithValue("@hi_feesetl_type", item.hi_feesetl_type);

                                cmd.Parameters.AddWithValue("@setl_id", item.setl_id);
                                cmd.Parameters.AddWithValue("@mdtrt_sn", item.mdtrt_sn);
                                cmd.Parameters.AddWithValue("@psn_no", item.psn_no);
                                cmd.Parameters.AddWithValue("@psn_cert_type", item.psn_cert_type);
                                cmd.Parameters.AddWithValue("@certno", item.certno);

                                cmd.Parameters.AddWithValue("@psn_name", item.psn_name);
                                cmd.Parameters.AddWithValue("@manu_lotnum", item.manu_lotnum);
                                cmd.Parameters.AddWithValue("@manu_date", item.manu_date);
                                cmd.Parameters.AddWithValue("@expy_end", item.expy_end);
                                cmd.Parameters.AddWithValue("@rx_flag", item.rx_flag);

                                cmd.Parameters.AddWithValue("@trdn_flag", item.trdn_flag);
                                cmd.Parameters.AddWithValue("@finl_trns_pric", item.finl_trns_pric);
                                cmd.Parameters.AddWithValue("@rxno", item.rxno);
                                cmd.Parameters.AddWithValue("@rx_circ_flag", item.rx_circ_flag);
                                cmd.Parameters.AddWithValue("@rtal_docno", item.rtal_docno);

                                cmd.Parameters.AddWithValue("@stoout_no", item.stoout_no);
                                cmd.Parameters.AddWithValue("@bchno", item.bchno);
                                cmd.Parameters.AddWithValue("@drug_trac_codg", item.drug_trac_codg);
                                cmd.Parameters.AddWithValue("@drug_prod_barc", item.drug_prod_barc);
                                cmd.Parameters.AddWithValue("@shelf_posi", item.shelf_posi);

                                cmd.Parameters.AddWithValue("@sel_retn_cnt", item.sel_retn_cnt);
                                cmd.Parameters.AddWithValue("@sel_retn_time", item.sel_retn_time);
                                cmd.Parameters.AddWithValue("@sel_retn_opter_name", item.sel_retn_opter_name);
                                cmd.Parameters.AddWithValue("@memo", item.memo);
                                cmd.Parameters.AddWithValue("@mdtrt_setl_type", item.mdtrt_setl_type);


                                cmd.Parameters.AddWithValue("@InputJson", InputJson);
                                cmd.Parameters.AddWithValue("@create_time", dateTime.ToString("yyyy-MM-dd HH-mm-ss"));
                                cmd.Parameters.AddWithValue("@update_time", dateTime.ToString("yyyy-MM-dd HH-mm-ss"));
                                await cmd.ExecuteNonQueryAsync();
                                cmd.Parameters.Clear();
                            }
                        }
                    }

                    return true;
                }
            }
        }

        /// <summary>
        /// 3507 上传记录删除
        /// </summary>
        /// <param name="fsiRequest">入参</param>
        /// <param name="CountrollerName">来源控制器名称</param>
        /// <returns>出参</returns>
        public async Task<bool> GoodsInfoDelete(FsiRequestHeader<InputGoodsInfoDelete> fsiRequest,
            string CountrollerName)
        {
            string fsiadmvs = fsiRequest.mdtrtarea_admvs.Substring(0, 2);
            string fixmedins_code = fsiRequest.fixmedins_code;
            string fixmedins_bchno = fsiRequest.Input.data.fixmedins_bchno;
            string inv_data_type = fsiRequest.Input.data.inv_data_type;
            string tablename = string.Empty;
            switch (inv_data_type)
            {
                case "1":
                    tablename = "fsi_goodsupload";
                    break;
                case "2":
                    tablename = "fsi_goodsupdate";
                    break;
                case "3":
                    tablename = "fsi_goodsbuy";
                    break;
                case "4":
                    tablename = "fsi_goodssell";
                    break;
                default:
                    throw new Exception($"校验进销存数据类型失败：进销存数据类型{inv_data_type}未被定义！");
            }

            string connectionString =
                $"Database={ApiDatainfo.mysqlDatabase};Data Source={ApiDatainfo.mysqlUrl};Port={ApiDatainfo.mysqlPost};UserId={ApiDatainfo.mysqlUser};Password={ApiDatainfo.mysqlPwd};Charset=utf8mb4;TreatTinyAsBoolean=false;Allow User Variables=True";
            using (var conn = new MySqlConnection(connectionString))
            {
                DateTime dateTime = DateTime.Now;
                string InputJson = JsonConvert.SerializeObject(fsiRequest);
                await conn.OpenAsync();
                using (MySqlCommand cmd = conn.CreateCommand())
                {
                    cmd.CommandText =
                        $"select * from {tablename}  where fixmedins_code =@fixmedins_code and fixmedins_bchno=@fixmedins_bchno and state =0";
                    cmd.Parameters.AddWithValue("@fixmedins_code", fsiRequest.fixmedins_code);
                    cmd.Parameters.AddWithValue("@fixmedins_bchno", fsiRequest.Input.data.fixmedins_bchno);
                    using (MySqlDataReader reader = (MySqlDataReader)await cmd.ExecuteReaderAsync())
                    {
                        cmd.Parameters.Clear();
                        DataTable dt = new DataTable();
                        dt.Load(reader);
                        if (dt.Rows.Count < 1)
                        {
                            throw new Exception(
                                $"查询{tablename}记录表失败！根据传入的机构代码：{fixmedins_code} 上传类型：{inv_data_type}  批次号：{fixmedins_bchno} 查询到的记录总数为：{dt.Rows.Count}");
                        }
                        else
                        {
                            cmd.CommandText =
                                $"update  {tablename} set state=1,update_time= @update_time where fixmedins_code =@fixmedins_code and fixmedins_bchno=@fixmedins_bchno and state =0 ";
                            cmd.Parameters.AddWithValue("@tablename", tablename);
                            cmd.Parameters.AddWithValue("@fixmedins_code", fsiRequest.fixmedins_code);
                            cmd.Parameters.AddWithValue("@fixmedins_bchno", fsiRequest.Input.data.fixmedins_bchno);
                            cmd.Parameters.AddWithValue("@update_time", dateTime.ToString("yyyy-MM-dd HH-mm-ss"));
                            await cmd.ExecuteNonQueryAsync();
                            cmd.Parameters.Clear();
                            return true;
                        }
                    }
                }
            }
        }

        /// <summary>
        /// 3568 库存上传(山东特有)
        /// </summary>
        /// <param name="fsiRequest">入参</param>
        /// <param name="CountrollerName">来源控制器名称</param>
        /// <returns>出参</returns>
        public async Task<bool> GoodsStocks(FsiRequestHeader<InputGoodStocks> fsiRequest, string CountrollerName)
        {
            string fsiadmvs = fsiRequest.mdtrtarea_admvs.Substring(0, 2);
            string connectionString =
                $"Database={ApiDatainfo.mysqlDatabase};Data Source={ApiDatainfo.mysqlUrl};Port={ApiDatainfo.mysqlPost};UserId={ApiDatainfo.mysqlUser};Password={ApiDatainfo.mysqlPwd};Charset=utf8mb4;TreatTinyAsBoolean=false;Allow User Variables=True";
            using (var conn = new MySqlConnection(connectionString))
            {
                DateTime dateTime = DateTime.Now;
                string InputJson = JsonConvert.SerializeObject(fsiRequest);
                await conn.OpenAsync();
                using (MySqlCommand cmd = conn.CreateCommand())
                {
                    cmd.CommandText =
                        "INSERT INTO `data`.`fsi_goodsstocks` (`fixmedins_code`, `fixmedins_name`, `prod_type`, " +
                        "`med_list_codg`, `fixmedins_hilist_id`, `fixmedins_hilist_name`, `inv_cnt`, `pric`, `stockstatus`, `memo`, " +
                        "`vali_flag`, `state`, `InputJson`, `create_time`, `update_time`) VALUES (@fixmedins_code, @fixmedins_name, @prod_type, " +
                        "@med_list_codg, @fixmedins_hilist_id, @fixmedins_hilist_name," +
                        " @inv_cnt, @pric,@stockstatus, @memo, @vali_flag,@state, @InputJson, @create_time, @create_time)";
                    cmd.Parameters.AddWithValue("@fixmedins_code", fsiRequest.fixmedins_code);
                    cmd.Parameters.AddWithValue("@fixmedins_name", fsiRequest.fixmedins_name);
                    cmd.Parameters.AddWithValue("@prod_type", fsiRequest.Input.invinfo.prod_type);
                    cmd.Parameters.AddWithValue("@med_list_codg", fsiRequest.Input.invinfo.med_list_codg);
                    cmd.Parameters.AddWithValue("@fixmedins_hilist_id", fsiRequest.Input.invinfo.fixmedins_hilist_id);
                    cmd.Parameters.AddWithValue("@fixmedins_hilist_name",
                        fsiRequest.Input.invinfo.fixmedins_hilist_name);
                    cmd.Parameters.AddWithValue("@inv_cnt", fsiRequest.Input.invinfo.inv_cnt);
                    cmd.Parameters.AddWithValue("@pric", fsiRequest.Input.invinfo.pric);
                    cmd.Parameters.AddWithValue("@stockstatus", fsiRequest.Input.invinfo.stockstatus);
                    cmd.Parameters.AddWithValue("@vali_flag", fsiRequest.Input.invinfo.vali_flag);
                    cmd.Parameters.AddWithValue("@memo", fsiRequest.Input.invinfo.memo);

                    cmd.Parameters.AddWithValue("@state", 0);
                    cmd.Parameters.AddWithValue("@InputJson", InputJson);
                    cmd.Parameters.AddWithValue("@create_time", dateTime.ToString("yyyy-MM-dd HH-mm-ss"));
                    cmd.Parameters.AddWithValue("@update_time", dateTime.ToString("yyyy-MM-dd HH-mm-ss"));
                    await cmd.ExecuteNonQueryAsync();
                    cmd.Parameters.Clear();
                }

                return true;
            }
        }

        /// <summary>
        /// 3569 企业信息上传(山东特有)
        /// </summary>
        /// <param name="fsiRequest">入参</param>
        /// <param name="CountrollerName">来源控制器名称</param>
        /// <returns>出参</returns>
        public async Task<bool> GoodsInformationInfo(FsiRequestHeader<InputGoodsInformationInfo> fsiRequest, string CountrollerName)
        {
            string fsiadmvs = fsiRequest.mdtrtarea_admvs.Substring(0, 2);
            string connectionString = $"Database={ApiDatainfo.mysqlDatabase};Data Source={ApiDatainfo.mysqlUrl};Port={ApiDatainfo.mysqlPost};UserId={ApiDatainfo.mysqlUser};Password={ApiDatainfo.mysqlPwd};Charset=utf8mb4;TreatTinyAsBoolean=false;Allow User Variables=True";
            using (var conn = new MySqlConnection(connectionString))
            {
                DateTime dateTime = DateTime.Now;
                string InputJson = JsonConvert.SerializeObject(fsiRequest);
                await conn.OpenAsync();
                using (MySqlCommand cmd = conn.CreateCommand())
                {
                   cmd.CommandText = "INSERT INTO `data`.`fsi_goodsinformationinfo` ( `fixmedins_code`, `fixmedins_name`, `fixmedins_hilist_id`, `entp_code`, " +
                                        "`entp_name`, `entp_type`, `busilicperson`, `manager`, `telephone`, `regaddress`, `address`, `province`, `city`, `county`, `city_flag`, " +
                                        "`openingbank`, `accountnumber`, `taxcode`, `isreceipttype`, `uscc`, `busilicissue`, `busilicexp`, `busilicissuedate`, `busiliccheckdate`," +
                                        " `businessscope`, `qaexpdate`, `qcmanager`, `licence`, `licenceexp`, `licenceissue`, `licencescope`, `licenceissuedate`, `InputJson`, `create_time`, " +
                                        "`update_time`) VALUES (@fixmedins_code, @fixmedins_name, @fixmedins_hilist_id, @entp_code, @entp_name, @entp_type,@busilicperson, @manager, " +
                                        "@telephone, @regaddress, @address, @province, @city, @county, @city_flag," +
                                        " @openingbank, @accountnumber, @taxcode, @isreceipttype, @uscc,@busilicissue, @busilicexp, @busilicissuedate, @busiliccheckdate, " +
                                        "@businessscope, @qaexpdate, @qcmanager, @licence, @licenceexp, @licenceissue, @licencescope, @licenceissuedate, @InputJson, @create_time, @update_time)";
                                    cmd.Parameters.AddWithValue("@fixmedins_code", fsiRequest.fixmedins_code);
                                    cmd.Parameters.AddWithValue("@fixmedins_name", fsiRequest.fixmedins_name);
                                    cmd.Parameters.AddWithValue("@fixmedins_hilist_id", fsiRequest.Input.entpbaseinfo.fixmedins_hilist_id);

                                    cmd.Parameters.AddWithValue("@entp_code", fsiRequest.Input.entpbaseinfo.entp_code);
                                    cmd.Parameters.AddWithValue("@entp_name", fsiRequest.Input.entpbaseinfo.entp_name);
                                    cmd.Parameters.AddWithValue("@entp_type", fsiRequest.Input.entpbaseinfo.entp_type);
                                    cmd.Parameters.AddWithValue("@busilicperson", fsiRequest.Input.entpbaseinfo.busilicperson);
                                    cmd.Parameters.AddWithValue("@manager", fsiRequest.Input.entpbaseinfo.manager); 
                                    cmd.Parameters.AddWithValue("@telephone", fsiRequest.Input.entpbaseinfo.telephone);
                                    cmd.Parameters.AddWithValue("@regaddress", fsiRequest.Input.entpbaseinfo.regaddress);
                                    cmd.Parameters.AddWithValue("@address", fsiRequest.Input.entpbaseinfo.address);
                                    cmd.Parameters.AddWithValue("@province", fsiRequest.Input.entpbaseinfo.province);
                                    cmd.Parameters.AddWithValue("@city", fsiRequest.Input.entpbaseinfo.city);
                                    cmd.Parameters.AddWithValue("@county", fsiRequest.Input.entpbaseinfo.county);
                                    cmd.Parameters.AddWithValue("@city_flag", fsiRequest.Input.entpbaseinfo.city_flag);
                                    cmd.Parameters.AddWithValue("@openingbank", fsiRequest.Input.entpbaseinfo.openingbank);
                                    cmd.Parameters.AddWithValue("@accountnumber", fsiRequest.Input.entpbaseinfo.accountnumber);
                                    cmd.Parameters.AddWithValue("@taxcode", fsiRequest.Input.entpbaseinfo.taxcode);
                                    cmd.Parameters.AddWithValue("@isreceipttype", fsiRequest.Input.entpbaseinfo.isreceipttype);
                                    cmd.Parameters.AddWithValue("@uscc", fsiRequest.Input.entpbaseinfo.uscc);
                                    cmd.Parameters.AddWithValue("@busilicissue", fsiRequest.Input.entpbaseinfo.busilicissue);
                                    cmd.Parameters.AddWithValue("@busilicexp", fsiRequest.Input.entpbaseinfo.busilicexp);
                                    cmd.Parameters.AddWithValue("@busilicissuedate", fsiRequest.Input.entpbaseinfo.busilicissuedate);
                                    cmd.Parameters.AddWithValue("@busiliccheckdate", fsiRequest.Input.entpbaseinfo.busiliccheckdate);
                                    cmd.Parameters.AddWithValue("@businessscope", fsiRequest.Input.entpbaseinfo.businessscope);
                                    cmd.Parameters.AddWithValue("@qaexpdate", fsiRequest.Input.entpbaseinfo.qaexpdate);
                                    cmd.Parameters.AddWithValue("@qcmanager", fsiRequest.Input.entpbaseinfo.qcmanager);
                                    cmd.Parameters.AddWithValue("@licence", fsiRequest.Input.entpbaseinfo.licence);
                                    cmd.Parameters.AddWithValue("@licenceexp", fsiRequest.Input.entpbaseinfo.licenceexp);
                                    cmd.Parameters.AddWithValue("@licenceissue", fsiRequest.Input.entpbaseinfo.licenceissue);
                                    cmd.Parameters.AddWithValue("@licencescope", fsiRequest.Input.entpbaseinfo.licencescope);
                                    cmd.Parameters.AddWithValue("@licenceissuedate", fsiRequest.Input.entpbaseinfo.licenceissuedate);
                                    cmd.Parameters.AddWithValue("@InputJson", InputJson);
                                    cmd.Parameters.AddWithValue("@create_time", dateTime.ToString("yyyy-MM-dd HH-mm-ss"));
                                    cmd.Parameters.AddWithValue("@update_time", dateTime.ToString("yyyy-MM-dd HH-mm-ss"));
                                    await cmd.ExecuteNonQueryAsync();
                                    cmd.Parameters.Clear();
                }

                return true;
            }
        }
        
        /// <summary>
        /// 3599 商品追溯码上传(山东特有)
        /// </summary>
        /// <param name="fsiRequest">入参</param>
        /// <param name="CountrollerName">来源控制器名称</param>
        /// <returns>出参</returns>
        public async Task<bool> GoodsSellTracInfo(FsiRequestHeader<InputGoodsSellTracInfo> fsiRequest, string CountrollerName)
        {
            string fsiadmvs = fsiRequest.mdtrtarea_admvs.Substring(0, 2);
            string connectionString = $"Database={ApiDatainfo.mysqlDatabase};Data Source={ApiDatainfo.mysqlUrl};Port={ApiDatainfo.mysqlPost};UserId={ApiDatainfo.mysqlUser};Password={ApiDatainfo.mysqlPwd};Charset=utf8mb4;TreatTinyAsBoolean=false;Allow User Variables=True";
            using (var conn = new MySqlConnection(connectionString))
            {
                DateTime dateTime = DateTime.Now;
                string InputJson = JsonConvert.SerializeObject(fsiRequest);
                await conn.OpenAsync();
                using (MySqlCommand cmd = conn.CreateCommand())
                {
                    cmd.CommandText = "INSERT INTO `data`.`fsi_goodsselltracinfo` ( `fixmedins_code`, `fixmedins_name`, `setl_id`, `setl_flag`, " +
                                        "`init_setl_id`, `fixmedins_hilist_id`, `fixmedins_hilist_name`, `med_type`, `mdtrt_sn`, `psn_no`, `psn_cert_type`, `certno`," +
                                        " `psn_name`, `bkkp_sn`, `trdn_flag`, `Setl_pric`, `sel_cnt`, `setl_time`, `prcunt`, `memo`, `med_list_codg`, `state`, `InputJson`," +
                                        " `create_time`, `update_time`) VALUES ( @fixmedins_code, @fixmedins_name, @setl_id, @setl_flag, @init_setl_id,@fixmedins_hilist_id, @fixmedins_hilist_name," +
                                        " @med_type, @mdtrt_sn, @psn_no, @psn_cert_type, @certno, @psn_name, @bkkp_sn,@trdn_flag, @Setl_pric, @sel_cnt," +
                                        "@setl_time, @prcunt, @memo, @med_list_codg, @state, @InputJson,@create_time, @update_time);";
                                    cmd.Parameters.AddWithValue("@fixmedins_code", fsiRequest.fixmedins_code);
                                    cmd.Parameters.AddWithValue("@fixmedins_name", fsiRequest.fixmedins_name);
                                    cmd.Parameters.AddWithValue("@setl_id", fsiRequest.Input.selinfo.setl_id);
                                    cmd.Parameters.AddWithValue("@setl_flag", fsiRequest.Input.selinfo.setl_flag);
                                    cmd.Parameters.AddWithValue("@init_setl_id", fsiRequest.Input.selinfo.init_setl_id);
                                    cmd.Parameters.AddWithValue("@fixmedins_hilist_id", fsiRequest.Input.selinfo.fixmedins_hilist_id);
                                    cmd.Parameters.AddWithValue("@fixmedins_hilist_name", fsiRequest.Input.selinfo.fixmedins_hilist_name);
                                    cmd.Parameters.AddWithValue("@med_type", fsiRequest.Input.selinfo.med_type);
                                    cmd.Parameters.AddWithValue("@mdtrt_sn", fsiRequest.Input.selinfo.mdtrt_sn);
                                    cmd.Parameters.AddWithValue("@psn_no", fsiRequest.Input.selinfo.psn_no);
                                    cmd.Parameters.AddWithValue("@psn_cert_type", fsiRequest.Input.selinfo.psn_cert_type);
                                    cmd.Parameters.AddWithValue("@psn_name", fsiRequest.Input.selinfo.psn_name);
                                    cmd.Parameters.AddWithValue("@bkkp_sn", fsiRequest.Input.selinfo.bkkp_sn);
                                    cmd.Parameters.AddWithValue("@trdn_flag", fsiRequest.Input.selinfo.trdn_flag);
                                    cmd.Parameters.AddWithValue("@Setl_pric", fsiRequest.Input.selinfo.Setl_pric);
                                    cmd.Parameters.AddWithValue("@sel_cnt", fsiRequest.Input.selinfo.sel_cnt);
                                    cmd.Parameters.AddWithValue("@setl_time", fsiRequest.Input.selinfo.setl_time);
                                    cmd.Parameters.AddWithValue("@prcunt", fsiRequest.Input.selinfo.prcunt);
                                    cmd.Parameters.AddWithValue("@memo", fsiRequest.Input.selinfo.memo);
                                    cmd.Parameters.AddWithValue("@med_list_codg", fsiRequest.Input.selinfo.med_list_codg);
                                    cmd.Parameters.AddWithValue("@state", 0);
                                    cmd.Parameters.AddWithValue("@InputJson", InputJson);
                                    cmd.Parameters.AddWithValue("@create_time", dateTime.ToString("yyyy-MM-dd HH-mm-ss"));
                                    cmd.Parameters.AddWithValue("@update_time", dateTime.ToString("yyyy-MM-dd HH-mm-ss"));
                                    await cmd.ExecuteNonQueryAsync();
                                    cmd.Parameters.Clear();
                }

                return true;
            }
        }
    }
}